#include <iostream>
#pragma once
const int NUMLEN = 201;
class num
{
private:
	int numn[NUMLEN];
	int length;
	bool neg;
public:
	num();
	num(const char *s);
	num operator=(const num &b);
	num operator+(const num &b);
	num operator-(const num &b);
	num operator*(const num &b);
	num operator*(const int b);
	num operator/(const num &b);
	bool operator<(const num &b);
	bool operator>(const num &b);
	bool operator==(const num &b);
	num operator<<(int n);
	friend std::istream& operator>>(std::istream &in, num &n);
	friend std::ostream& operator<<(std::ostream &out, const num &n);
};

num::num()
{
	memset(numn, 0, sizeof(numn));
	length = 0;
	neg = false;
}

num::num(const char *s)
{
	memset(numn, 0, sizeof(numn));
	for (int i = strlen(s) - 1; i >= 0; i--)
	{
		numn[i] = s[strlen(s) - i - 1] - '0';
	}
	if (!s){ length = 0; }
	else{ length = strlen(s); }
	neg = false;
}

std::istream& operator>>(std::istream &in, num &n)
{
	char str[NUMLEN];
	std::cin >> str;
	for (int i = strlen(str) - 1; i >= 0; i--)
	{
		n.numn[i] = str[strlen(str) - i - 1] - '0';
	}
	n.length = strlen(str);

	return in;
}

std::ostream& operator<<(std::ostream &out, const num &n)
{
	if (n.length <= 0)
	{
		std::cout << '0';
	}
	if (n.neg == true)
	{
		std::cout << '-';
	}
	for (int i = n.length; i > 0; i--)
	{
		std::cout << n.numn[i - 1];
	}

	return out;
}

bool num::operator<(const num &b)
{
	int i;
	if (neg == false && b.neg == true)
	{
		return true;
	}
	else if (neg == true && b.neg == true)
	{
		for (length>b.length ? i = length : i = b.length; i >= 0; i--)
		{
			if (numn[i]<b.numn[i])
			{
				return false;
			}
			else
			{
				return true;
			}
			return false;
		}
	}
	for (length>b.length ? i = length : i = b.length; i >= 0; i--)
	{
		if (numn[i]<b.numn[i])
		{
			return true;
		}
		else if (numn[i]>b.numn[i])
		{
			return false;
		}
	}
	return false;
}

bool num::operator==(const num &b)
{
	int i;
	for (length>b.length ? i = length : i = b.length; i >= 0; i--)
	{
		if (numn[i] != b.numn[i])
		{
			return false;
		}

	}
	return true;
}

bool num::operator>(const num &b)
{
	if (*this < b || *this == b)
	{
		return false;
	}
	return true;
}

num num::operator<<(int n)
{
	num temp;
	for (int i = 0; i < length; i++)
	{
		temp.numn[i + n] = numn[i];
	}
	temp.length = length + n;
	return temp;

}

num num::operator=(const num &b)
{
	memset(numn, 0, sizeof(numn));
	length = b.length;
	neg = b.neg;
	for (int i = 0; i < length; i++)
	{
		numn[i] = b.numn[i];
	}
	return *this;
}

num num::operator*(const int b)
{
	num temp;
	int t = 0;
	int tmp = 0;
	for (int i = 0; i < length; i++)
	{
		tmp = numn[i] * b + t;
		temp.numn[i] = tmp % 10;
		t = tmp / 10;
		temp.length++;
	}
	if (t != 0)
	{
		temp.numn[length] = t;
		temp.length++;
	}
	return temp;
}

num num::operator+(const num &b)
{
	num temp;
	int tmp = 0, t = 0;
	for (int i = 0; i <length || i <b.length; i++)
	{
		tmp = numn[i] + b.numn[i] + t;
		if (tmp >= 10)
		{
			temp.numn[i] = tmp % 10;
			t = 1;
		}
		else
		{
			temp.numn[i] = tmp;
			t = 0;
		}
		temp.length++;
	}
	if (t != 0)
	{
		temp.numn[temp.length] = t;
		temp.length++;
	}
	return temp;
}

num	num::operator-(const num &b)
{
	num temp;
	int tmp;
	int t = 0;
	const num *tmpa = nullptr;
	const num *tmpb = nullptr;
	if (*this < b)
	{
		tmpa = &b;
		tmpb = this;
		temp.neg = true;
	}
	else
	{
		tmpa = this;
		tmpb = &b;
	}
	for (int i = 0; i < tmpa->length; i++)
	{
		tmp = tmpa->numn[i] - tmpb->numn[i] - t;
		if (tmp < 0)
		{
			temp.numn[i] = tmp + 10;
			t = 1;
		}
		else
		{
			temp.numn[i] = tmp;
			t = 0;
		}
		temp.length++;
	}
	for (int i = temp.length; i > 0; i--)
	{
		if (temp.numn[i - 1] != 0)
		{
			break;
		}
		else
		{
			temp.length--;
		}
	}

	return temp;
}

num num::operator*(const num &b)
{
	int t = 0;
	int tmp = 0;
	num temp;
	for (int i = 0; i < b.length; i++)
	{
		temp = temp + ((*this * b.numn[i]) << i);
	}
	return temp;
}

num num::operator/(const num &b)
{
	int n = 0;
	num temp;
	num tempb = b;
	num tempa = *this;
	num tempc;
	temp.length = tempa.length - tempb.length + 1;
	for (int i = length - b.length; i >= 0; i--)
	{
		tempc = (tempb << i);
		while (!(tempa<tempc))
		{
			tempa = tempa - tempc;
			temp.numn[i]++;
		}

	}
	for (int i = temp.length; i > 0; i--)
	{
		if (temp.numn[i - 1] != 0)
		{
			break;
		}
		else
		{
			temp.length--;
		}
	}
	if (temp.length < 0)
	{
		temp.length = 0;
	}
	return temp;
}